package pl.us.ij.plugins.segmentation.forms;

import pl.us.ij.plugins.segmentation.infrastructure.ICommandInvokeHandler;

import javax.swing.*;
import java.awt.event.ActionEvent;

/**
* Created by IntelliJ IDEA.
* User: Przemek
* Date: 2010-05-26
* Time: 21:55:31
* To change this template use File | Settings | File Templates.
*/
public class CommandAction extends AbstractAction {

    private ICommandInvokeHandler commandInvokeHandler;
    private ICommandParamGather commandParamGather;
    private String commandName;

    public CommandAction(String text, String commandName, ICommandInvokeHandler invokeHandler, ICommandParamGather paramGather) {
        super(text);

        if (invokeHandler == null)
            throw new IllegalArgumentException("invokeHandler may not be a null.");

        if (paramGather == null)
            throw new IllegalArgumentException("paramGather may not be a null.");

        this.commandInvokeHandler = invokeHandler;
        this.commandParamGather = paramGather;
        this.commandName = commandName;
    }

    public void actionPerformed(ActionEvent e) {
        commandInvokeHandler.invoke(commandName, commandParamGather.getCommandParams());
    }
}
